<?php  
namespace app\admin\controller;
// use think\Controller;
class News extends Base{
	public function index(){
		return view();
	}
	public function newsclassify_list(){
		$arr=db('news')->where('type=0')->paginate(5); 
		return view('',['arr'=>$arr]);
	}
	public function newsclassify_add(){
		return view();
	}
	public function newsclassify_insert(){
		$rst=db('news')->insert($_POST);
		if($rst){
			$this->success('添加成功','newsclassify_list');
		}else{
			$this->error('添加失败','newsclassify_list');
		}
	}
	public function newsclassify_edit(){
		if(db('news')->update($_POST)){
			$this->success('修改成功','newsclassify_list');
		}else{
			$this->error('修改失败','newsclassify_list');
		}
	}
	public function newsclassify_del($id){
		$arr=db('news')->find($id);
		if(db('news')->where('type','1')->where('typeclass',$arr['typeclass'])->find()){
			$this->error('该新闻类别下含有新闻，不可删除','newsclassify_list');
		}
		if(db('news')->delete($id)){
			$this->success('删除成功','newsclassify_list');
		}else{
			$this->error('删除失败','newsclassify_list');
		}
	}


	public function news_list(){
		$arr=db('news')->where('type=1')->paginate(5);
		return view('',['arr'=>$arr]);
	}
	public function news_add(){
		$arr=db('news')->where('type=0')->select();
		// halt($arr);
		return view('',['arr'=>$arr]);
	}
	public function news_insert(){
		$_POST['date']=strtotime($_POST['date']);
		if(db('news')->insert($_POST)){
			$this->success('添加成功','news_list');
		}else{
			$this->error('添加失败','news_list');
		}
	}
	public function news_del($id){
		$arr=db('news')->find($id);
		if(db('news')->delete($id)){
			$this->success('删除成功','news_list');
		}else{
			$this->error('删除失败','news_list');
		}
	}
	public function news_edit(){
		// halt($_GET);
		$arr=db('news')->where('type=0')->select();
		// halt($_GET);
		$old=db('news')->find($_GET['id']);
		// halt($old);
		return view('',['arr'=>$arr,'old'=>$old]);
	}
	public function news_update(){
		// halt($_POST);
		// echo date('y/m/d',$olddate);
		// halt($olddate);
		// echo($_POST['date']);
		$arr=db('news')->find($_POST['id']);
		if(empty($_POST['date'])){
			$_POST['date']=$arr['date'];
		}else{
			$_POST['date']=strtotime($_POST['date']);
		}
		// halt($_POST['date']);
		if(db('news')->update($_POST)){
			$this->success('修改成功','news_list');
		}else{
			$this->error('修改失败','news_list');
		}
	}


	public function newscomment_list(){
		$arr=db('news')->where('type=2')->paginate(5);
		// halt($arr);
		return view('',['arr'=>$arr]);
	}
	public function newscomment_del($id){
		$arr=db('news')->find($id);
		if(db('news')->delete($id)){
			$this->success('删除成功','newscomment_list');
		}else{
			$this->error('删除失败','newscomment_list');
		}
	}
	public function newscomment_audit(){
		$old=db('news')->find($_GET['id']);
		// halt($old);
		return view('',['old'=>$old]);
	}
	public function newscomment_audit_check(){
		// halt(input());
		if(db('news')->update($_POST)){
			$this->success('审核成功','newscomment_list');
		}else{
			$this->error('审核失败','newscomment_list');
		}
	}
}
